# -*- coding: utf-8 -*-
import scrapy
from scrapy import Request
from scrapy.loader import ItemLoader
from scrapy import signals
from selenium import webdriver
# from scrapy.xlib.pydispatch import dispatcher
from scrapy_ndd.items import ScrapyCoinItem
import time


class CoinPriceSpider(scrapy.Spider):
    name = 'coin_price'
    allowed_domains = ['feixiaohao.com']
    start_urls = [
                    'https://www.feixiaohao.com/search/?word=BTC',
                    'https://www.feixiaohao.com/search/?word=ETH',
                  ]

    def __init__(self):
        self.browser = webdriver.Chrome()
        super(CoinPriceSpider, self).__init__()
        # 使用信号量，当spider关闭的时候调用spider_closed函数关闭浏览器
        # dispatcher.connect(self.spider_closed, signals.spider_closed)

    def spider_closed(self, spider):
        self.browser.quit()

    def parse(self, response):
        print(response.text)
        # item_loader = ItemLoader(item=ScrapyCoinItem(), response=response)
        # item_loader.add_css("new_url", "h1 strong a::attr(href)")
        #
        # ndd_item = item_loader.load_item()
        # yield ndd_item

